/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package giormi;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
/**
 *
 * @author Ling
 */
public class F_addproduct {
    private String p_status;
    private String p_barcode;
    private String p_name;
    private String p_packing;
    private String p_netweight;

    public void setP_barcode(String p_barcode) {
        this.p_barcode = p_barcode;
    }

    public void setP_name(String p_name) {
        this.p_name = p_name;
    }

    public void setP_netweight(String p_netweight) {
        this.p_netweight = p_netweight;
    }

    public void setP_packing(String p_packing) {
        this.p_packing = p_packing;
    }

    public void setP_status(String p_status) {
        this.p_status = p_status;
    }

    private Connection conn;
    private String SQLStatement;
    private String URL;
    private Statement stmt;
    public ResultSet rset;

    public void connect(){
        try{
            DBConnection db = new DBConnection();
            conn = DBConnection.get();
            stmt = conn.createStatement();
        }
        catch(Exception e){
            System.out.println(e.getMessage());
            JOptionPane.showMessageDialog(null,e.getMessage(),"ERROR", JOptionPane.WARNING_MESSAGE);
        }
    }

    public void disconnect(){
        try{
            stmt.close();
            conn.close();
        }
        catch(Exception ex){
            System.out.println(ex.getMessage());
            JOptionPane.showMessageDialog(null,ex.getMessage(),"ERROR", JOptionPane.WARNING_MESSAGE);
        }
    }

    public void addproduct(){
        try{
           SQLStatement = "INSERT INTO product "+
                   "(p_status, p_barcode, p_name, p_packing, p_netweight) VALUES"+
                   "('"+p_status+"','"+p_barcode+"','"+p_name+"','"+p_packing+"','"+p_netweight+"')";
            stmt.executeUpdate(SQLStatement);
        }
        catch(Exception ex){
            System.out.println(ex.getMessage());
            JOptionPane.showMessageDialog(null,ex.getMessage(),"ERROR", JOptionPane.WARNING_MESSAGE);
        }
    }
}
